<template>
  <div id="notice-list">
    <div class="page-card">
      <div class="page-header">
        <div class="page-title">公告列表</div>
      </div>
      <div class="page-content">
        <div class="list">
          <div class="list-cell" v-for="(item,index) in tableData" :key="index" @click="toNoticeDetail(item.id)">
            <div>{{item.title}}</div>
            <div>{{item.create_time}}</div>
          </div>
        </div>
        <div class="page-footer">
         <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="page"
          :page-sizes="[10, 15, 20, 25]" :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper"
          :total="pageTotal"></el-pagination>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  import {
    apiMessageList
  } from '../../request/api.js'
  import { mapGetters } from 'vuex';
  export default {
    data(){
      return {
        page: 1,
        pageSize: 10,
        pageTotal: 0,
        tableData: [],
        userToken: window.localStorage.getItem('token')
      }
    },
    created() {
      this.getTableData()
    },
    methods:{
      getTableData(){
        this.$isClick(true);
        apiMessageList({
          page: this.page,
          pageSize: this.pageSize,
          token: this.userToken
        }).then(res =>{
          this.$isClick(false);
           if (res.code == 1){
            this.tableData = res.msg.message_list
            this.pageTotal = res.msg.all_num
           } else {
             this.$message.error(res.msg);
           }
        }).catch(res => {
          this.$isClick(false);
            this.$message.error(res.msg)
        })
      },
      handleSizeChange(val) {
      	this.pageSize = val
        this.getTableData()
      },
      handleCurrentChange(val) {
      	this.page = val
      	this.getTableData()
      },
      toNoticeDetail(id){
         this.$router.push("./noticeDetail?id=" + id);
      }
    }
  }
</script>

<style lang="less">
  #notice-list{
    .page-card {
      background: #FFFFFF;
      margin-bottom: 16px;
      box-shadow: 0px 0px 5px 0px rgba(0, 0, 0, 0.1);
      border-radius: 5px;
      .page-header {
        background: #ecf5ff;
        padding: 10px;
        display: flex;
        align-items: center;
        margin-bottom: 16px;
        .page-title {
          line-height: 20px;
          border-left: 3px solid #666666;
          padding-left: 10px;
          font-size: 16px;
          font-weight: 700;
          color: #333333;
          width: 150px;
        }
      }
      .page-content {
        padding: 10px 20px ;
        .list-cell {
          display: flex;
          align-items: center;
          justify-content:space-between;
          font-size: 14px;
          color: #333333;
          border-bottom: 1px dashed #e0e0e0;
          padding: 16px;
          cursor: pointer;
        }
        .page-footer {
          text-align: right;
          margin-top: 32px;
        }
      }
    }
  }
</style>
